//
//  LWVisitorTabVC.swift
//  Swift_Weibo_HLW
//
//  Created by huanglinwang on 16/9/20.
//  Copyright © 2016年 Linwang. All rights reserved.
//

import UIKit

class LWVisitorTabVC: UITableViewController, LWVisitorViewDelegate {

    
    var visitorView: LWVisitorView?
    
    var isLogin: Bool = LWUserAccountViewModel.sharedUserAccoutnViewModel.isLogin
    
    //不希望使用系统提供的视图就重写loadView
    //自定义View视图  重写loadView是自定义控制器中的视图
    override func loadView() {
        
        if isLogin{
            super.loadView()
        }else{
            //自己提供的视图
            visitorView = LWVisitorView()
//            visitorView.backgroundColor = UIColor.red
            
            visitorView?.delegate = self
            
            //访客视图登陆按钮点击事件
            visitorView?.loginClosure = {
                print("我是访客视图调用过来的闭包")
            }
            
            
            view = visitorView
            
            //未登录条件下执行导航添加按钮
            setupUINav()
            
        }
        
    }
    
    private func setupUINav(){
        
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", target: self, action: #selector(visitorLoginViewWillLogin))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(visitorLoginViewWillRegister))
        
    }
    
    
    //导航栏按钮点击事件
    @objc private func loginAction() {
        print("xx");
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    func visitorLoginViewWillLogin() {
        print("登陆")
        let oAuthVC = LWOAuthVC()
        let navVC = UINavigationController(rootViewController: oAuthVC)
        present(navVC, animated: true, completion: nil)
    }
    
    func visitorLoginViewWillRegister() {
        print("注册")
    }
    
}
